package com.zs.diveinspringbootkotlin.bootstrap

import com.zs.diveinspringbootkotlin.condition.ConditionOnSystemProperty
import com.zs.diveinspringbootkotlin.service.CalculateService
import org.springframework.boot.WebApplicationType
import org.springframework.boot.builder.SpringApplicationBuilder
import org.springframework.context.annotation.Bean

/**
 *
 * @description
 * @author madison
 * @date 2021/6/3 22:33
 *
 */
class ConditionOnSystemPropertyBootstrap {
    @Bean
    @ConditionOnSystemProperty(name = "user.name", value = "madison")
    fun helloWorld(): String {
        return "hello world madison"
    }
}

fun main(array: Array<String>) {
    val context = SpringApplicationBuilder(ConditionOnSystemPropertyBootstrap::class.java)
        .web(WebApplicationType.NONE)
        .run(*array)

    // 通过名称和类型获取helloWorld
    val helloWorld = context.getBean("helloWorld")
    println("helloWorld Bean:$helloWorld")

    // 关闭上下文
    context.close()
}